import { h, defineComponent } from "vue";
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
const r: Record<string, any> = {}
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    // app.component(key, component)
    r[key] = component
}
export default defineComponent({
    name: "icon",
    props: {
        iconKey: {
            default: "",
            type: String,
        },
        size: {
            default: "16px",
            type: String,
        }
    },
    setup(props) {
        if (!props.iconKey) {
            console.error("使用icon必须穿入key值")
            return () => h('div')
        }
        if (props.iconKey in ElementPlusIconsVue) {
            return () => h(r[props.iconKey],
                {
                    style: {
                        width: props.size,
                        height: props.size
                    }
                })
        } else {
            return () => h('svg', {
                class: "icon",
                style: {
                    width: props.size,
                    height: props.size,
                },
                "aria-hidden": "true"
            }, [
                h('use',{
                    "xlink:href":`${props.iconKey}`
                })
            ])
        }
    },
}
)